package com.cardosystems.tests.analyzers;

import com.cardosystems.infra.enums.PSKeys;

import jsystem.extensions.analyzers.text.FindText;
import jsystem.framework.analyzer.AnalyzerParameterImpl;

public class PSKeyAnalyzer extends AnalyzerParameterImpl {

	private PSKeys key;
	private int wordIndex;
	private String expectedWord;

	public PSKeyAnalyzer(PSKeys key, int world, String expectedWord) {
		super();
		this.key = key;
		this.wordIndex = world;
		this.expectedWord = expectedWord;
	}

	@Override
	public void analyze() {
		String actualKey = testAgainst.toString();
		FindText findText = new FindText(key.getKey() + " = (.*)", true, false,
				1);
		findText.setTestAgainst(actualKey);
		findText.analyze();
		String pskey = findText.getCounter();
		String[] words = pskey.split(" ");
		if (words[wordIndex+2].equals(expectedWord)) {
			title = pskey + ", Word #" + wordIndex
					+ " was " + expectedWord + " as Expexted";
			status = true;
		} else {
			title = pskey + ", Word #" + wordIndex
					+ " was " + words[wordIndex+2] + " and not " + expectedWord
					+ " as Expexted";
			status = false;
		}

	}

}
